/*
 * author: VDaras
 */


#ifndef KEYMAPPER_H
#define	KEYMAPPER_H

#include <map>
#include <SDL/SDL.h>
#include <string>


/**
 * Class that maps SDL Keys to strings.
 */

struct InputKey
{
    SDLKey key;
    SDLMod mod;
};

struct CompareKeys
{
    bool operator()(const InputKey& a,const InputKey& b) const
    {
        return (a.key + 512 * a.mod) <  (b.key + 512 * b.mod);
    }
};

class KeyMapper
{
    typedef std::map< std::string ,SDLKey> KeyMap;
    typedef std::map< InputKey, std::string,CompareKeys > AssociationMap;
    typedef std::map< std::string,SDLMod > ModMap;

private:
    AssociationMap m_keyAssociations;
    KeyMap m_enumMap;
    ModMap m_modMap;
    SDLMod validMods;
public:

    KeyMapper();

    ~KeyMapper();


    /**
     * Creates a map associating sdlk values with a literal
     */
    void CreateAsciiMap();

    /**
     * Creates a map associating sdlmod values with a literal
     */
    void CreateModMap();

    /**
     * Reads key map file
     */
    bool ReadFile(char const * group = NULL);

    /**
     * Associates an SDLKey with a string. E.g associate SDLK_SPACE
     * with "JUMP".
     *
     * @param association - the string to associate the key with
     * @param key - the key to associate (part 1 of the key)
     * @param mod - the mod to associate (part 2 of the key)
     */
    void AssociateKey(const std::string &association, SDLKey key, SDLMod mod = KMOD_NONE);


    /**
     * Returns the string that the key SDLkey is mapped to.
     *
     * @param retval - OUTPUT parameter, stores the associated string in here.
     * @param key
     * @param mod 
     * @return a boolean value indicating if the key SDLKey is mapped to a value
     */

    bool MapKey(std::string &retval,SDLKey key,SDLMod mod/*= NONE*/) const;
    
    SDLMod GetValidMods() const;
};

#endif	/* KEYMAPPER_H */

